<?php 


header("Content-type: text/html; charset=utf-8");


//计算脚本运行时间
function countTime()
{
	static $time=0;

	if($time){
		echo microtime(true)-$time;
	}else{
		$time = microtime(true);
	}
}

// 存储单位转换
function F($size)
{
	if($size>pow(1024,3)){
		return round($size/pow(1024,3),1)."GB";
	}elseif($size>pow(1024,2)){
		return round($size/pow(1024,2),1)."MB";
	}elseif($size>pow(1024,1)){
		return round($size/pow(1024,1),1)."KB";
	}else{
		return $size."B";
	}
}


// 存储单位转换
function Smarty_F($params, $smarty)
{

	$size = $params['data'];
	if($size>pow(1024,3)){
		return round($size/pow(1024,3),1)."GB";
	}elseif($size>pow(1024,2)){
		return round($size/pow(1024,2),1)."MB";
	}elseif($size>pow(1024,1)){
		return round($size/pow(1024,1),1)."KB";
	}else{
		return $size."B";
	}
}

function Smarty_userlist($params, $content, $smarty, &$repeat, $template='')
{
	$row = $params['row'];
	$sql = "select * from question limit $row";
	$res = M()->query($sql);
	// $smarty->assign('list','909090');
	$smarty->assign('list',$res);
	return $content;
}

function Smarty_CT($string, $format = null, $default_date = '', $formatter = 'auto')
{
	$time = $string;
	$diff =  time()-$time;



	if($diff<pow(60, 2)){
		return ceil($diff/pow(60, 1))."分钟之前";
	}elseif($diff<(pow(60, 2)*24)){

		return ceil($diff/pow(60, 2))."小时之前";
	}elseif($diff<(pow(60, 2)*24*7)){
		return ceil($diff/(pow(60, 2)*24))."天之前";
	}else{
		return date("Y-m-d H:i:s",$time);
	}

}

// 获取网站配置信息
function C($option)
{
	$configs = include CONFIG_PATH.'Config.php';

	if(isset($configs[$option])){
		return $configs[$option];
	}else{
		return " ";
	}
}

// 实例化数据库对象
function M($table='')
{
	return new Model($table);
}


//递归删除目录
function DelDir($path)
{
	$path = rtrim($path,'/');
	$paths = glob($path.'/*');
	foreach ($paths as $v) {
		if (is_dir($v)) {
			DelDir($v);
		}else{
			unlink($v);
		}
	}

	rmdir($path);
}

/**
 * 移动目录
 * @static
 * @param str $src 源目录
 * @param str $des 目标目录
 * @return null
 */
function CopyDir($src,$des) 
{
	mkdir($des,0777,true);
	$src = rtrim($src,'/');
	$des = rtrim($des,'/');
	$paths = glob($src.'/*');

	foreach ($paths as $value) {
		if(is_dir($value)){
			// echo $des.'/'.basename($value);
			CopyDir($value,$des.'/'.basename($value));
		}else{
			// 组要移到的目标文件路径
			copy($value, $des.'/'.basename($value));
		}
	}

}


function D($name)
{
	$classname = $name.'Model';
	return new $classname;
}

















 ?>